//
//  WBNetworkTools.m
//  oc封装网络请求工具类
//
//  Created by KIMI on 16/9/21.
//  Copyright © 2016年 KIMI. All rights reserved.
//

#import "WBNetworkTools.h"
@implementation WBNetworkTools

+ (instancetype)sharedNetWorkTooles{
    
    static WBNetworkTools *tools;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        tools = [[WBNetworkTools alloc]init];
        //可以接受响应类型的数据
        tools.responseSerializer.acceptableContentTypes = [tools.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];
    });
    return tools;
}
    
//封装网络请求
- (void)requestWithType :(requestType)type andURLStr :(NSString *)urlStr andParams :(id)params andCallBack :(void(^)(id response,NSError *error))callBack{
    
    if(type == GET){
        
        [self GET:urlStr parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            callBack(responseObject,nil);
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            callBack(nil,error);
        }];
    }else{
        
        [self POST:urlStr parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            callBack(responseObject,nil);
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            callBack(nil,error);
        }];
    }
    
    
    
}
@end
